import time
import logging
from common import Dnconsole

import logging

logging.basicConfig(
    filename="../canhx_log.log",
    format='%(asctime)s - %(name)s - %(pathname)s - %(lineno)d - %(levelname)s - %(message)s',
    datefmt='%d-%b-%y %H:%M:%S',
    level=logging.INFO
)


def main():
    # 请根据自己电脑配置
    # # console = 'D:\\Changzhi\\dnplayer2\\dnconsole.exe '
    # console = 'C:\\leidian\\LDPlayer9\\dnconsole.exe'
    # # ld = 'D:\\Changzhi\\dnplayer2\\ld.exe '
    # ld = 'D:\\leidian\\LDPlayer9\\ld.exe '
    # # share_path = 'F:/share/Pictures'
    # share_path = 'C:/Users/Leq/Documents/leidian9/Pictures'
    dnconsole = Dnconsole()

    # 查看可用的模拟器列表
    ld_list = dnconsole.get_list()
    # print("INFO: 可用的模拟器列表:\n {}".format(ld_list))

    logging.info("INFO: 可用的模拟器列表:\n {}".format(ld_list))

    # 查看正在运行的模拟器
    run_list = dnconsole.list_running()
    # print("INFO: 正在运行的模拟器列表:\n {}".format(run_list))
    logging.info("INFO: 正在运行的模拟器列表:\n {}".format(run_list))

    # 启动模拟器
    res = dnconsole.launch(0)
    print(res)
    time.sleep(5)

    # 设置分辨率
    dnconsole.set_screen_size(0)

    # 看安装的软件列表
    dnconsole.get_package_list(0)

    # 打开b站app
    res = dnconsole.invokeapp(0, "tv.danmaku.bili")
    print(res)
    # time.sleep(5)

    # 点击一个位置 搜索
    dnconsole.touch(0, 300, 120)
    dnconsole.touch(0, 300, 80)
    dnconsole.input_text(0, "11111111")
    dnconsole.touch(0, 1000, 100)

    # 把需要点击的内容的id排序（根据优先级）

    # 关闭b站app
    res = dnconsole.stopapp(0, "tv.danmaku.bili")
    print(res)


if __name__ == '__main__':
    main()
